[SUBROUTINE]
version = 1.15
icon = lathe-tool-change.png
name = _("Tool Change")
type = tool_change
help = _("<b>Change Tool and/or settings</b>&#10;Changes setting accordingly even if disabled")
order = act h1 dnum us tlc spindle_dir cooling h2 mode speed surf_speed h8 r_feed c_dpt h4 f_feed fc_dpt hc rx rix rz

[PARAM_ACT]
name = _("Active")
icon = enable.png
type = bool
value = 1
tool_tip = _("Params will be set even if disabled")

[PARAM_H1]
name = _("Tool and usage")
type = sub-header

[PARAM_DNUM]
name = _("Tool number")
header = h1
type = tool
icon = lathe-tool.png
tool_tip = _("Select from tool table")
value = 0

[PARAM_US]
name = _("Usage")
header = h1
type = combo
options = _("Roughing and finishing=0:Roughing=1:Finishing=2")
tool_tip = _("Select usage for this tool")
value = 0
icon = tool-usage.png

[PARAM_TLC]
name = _("Use length comp")
icon = comp-l.png
type = combo
options = _("No=0:Already mounted and touched=3:From tool table=1:Table and probe=2")
header = h1
value = 1
tool_tip = _("Use G43 and probe if setup")

[PARAM_COOLING]
name = _("Use cooling")
header = h1
type = combo
options = _("None=9:Flood=8:Mist=7")
icon = snowflake.png
tool_tip = _("Use flood, mist or none")
value = 8

[PARAM_SPINDLE_DIR]
name = _("Start spindle")
header = h1
type = combo
options = _("No=5:Clockwise=3:Counter-clockwise=4")
icon = lathe-dir.png
tool_tip = _("Select spindle rotation")
value = 3

[PARAM_H2]
name = _("Spindle control")
type = sub-header

[PARAM_MODE]
name = _("Mode")
icon = lathe-chuck.png
type = combo
header = h2
options = _("Constant surface speed=0:RPM=1")
value = 1
value_changed = 
	parent.get_param('param_surf_speed').set_grayed(new_val == '1')
	if new_val == '1' :
		parent.get_param('param_speed').attr['name'] = _("'Spindle speed'")
	else :
		parent.get_param('param_speed').attr['name'] = _("'Max spindle'")

[PARAM_SPEED]
name = _("Max spindle")
header = h2
type = int
minimum_value = 10
icon = tool-spindle.png
tool_tip = _("RPM spindle speed")
value = 500

[PARAM_SURF_SPEED]
name = _("Surface speed")
header = h2
type = int
minimum_value = 1
icon = tool-spindle.png
tool_tip = _("Constant spindle speed")
value = 100
grayed = 0

[PARAM_H8]
name = _("Roughing")
type = sub-header
tool_tip = _("Set these when usage is roughing")

[PARAM_R_FEED]
name = _("Feed")
header = h8
type = float
icon = lathe-feed.png
tool_tip = _("Feed at 100% engagement")
minimum_value = 0.0
not_allowed = 0
value = 3.0
metric_value = 75.0

[PARAM_C_DPT]
name = _("Cut depth")
type = float
minimum_value = 0.0
tool_tip = _("Depth of cutter engagment in machine units per pass")
value = 0.02
header = h8
metric_value = 0.5
not_allowed = 0
icon = lathe-depth-step.png

[PARAM_H4]
name = _("Finishing")
type = sub-header
tool_tip = _("Set these when usage include finishing")

[PARAM_F_FEED]
name = _("Feed")
header = h4
type = float
icon = lathe-feed.png
tool_tip = _("Feed at 100% engagement")
minimum_value = 0.0
not_allowed = 0
value = 2.0
metric_value = 50.0

[PARAM_FC_DPT]
name = _("Cut depth")
type = float
minimum_value = 0.0
tool_tip = _("Depth of cutter engagment in machine units per pass")
value = 0.01
header = h4
metric_value = 0.25
not_allowed = 0
icon = lathe-depth-step.png

[PARAM_HC]
name = _("Clearances")
type = sub-header

[PARAM_RX]
name = _("Retract X")
type = float
value = 0.04
metric_value = 1.0
minimum_value = 0.0
not_allowed = 0
header = hc
icon = lx-clear.png
tool_tip = _("Retract distance on multiple passes")

[PARAM_RIX]
name = _("Int. retract X")
type = float
value = 0.040
metric_value = 1.0
minimum_value = 0.0
not_allowed = 0
tool_tip = _("Retract distance")
header = hc
icon = ix-clear.png

[PARAM_RZ]
name = _("Retract Z")
type = float
value = 0.04
metric_value = 1.0
minimum_value = 0.0
not_allowed = 0
header = hc
icon = lz-clear.png
tool_tip = _("Retract distance on multiple passes")

[DEFINITIONS]
content =
;	<eval>self.include_once(file name here)</eval>

[INIT]
content =
	a = parent.get_param('param_mode').get_attr('value')
	parent.get_param('param_surf_speed').set_grayed(a == '1')
	if a == '1' :
		parent.get_param('param_speed').attr['name'] = _("'Spindle speed'")
	else :
		parent.get_param('param_speed').attr['name'] = _("'Max spindle'")

[VALIDATION]
content =
	TOOL_TABLE.save_tool_orient(#param_dnum)

[CALL]
content =
	(begin #sub_name)
	(author : Fernand Veilleux)
	
	o<#self_id_tlc> if [[#param_tlc EQ 3] AND [#param_dnum GT 0]]
		M61 Q#param_dnum
	o<#self_id_tlc> endif
	
	o<#self_id_act> if [#param_act AND [#param_dnum NE #5400]]    
		M9  (coolant off)
		T#param_dnum M6
	o<#self_id_act> endif
	
	o<#self_id_lc> if [#param_tlc GE 1]
		G43 H#param_dnum
	o<#self_id_lc> endif

	#<_tool_usage>   =  #param_us
	#<_spindle_dir>  =  #param_spindle_dir
	#<_cooling_mode> =  #param_cooling
	
	#<_rough_feed>   =  #param_r_feed
	#<_rough_cut>    =  #param_c_dpt
	
	#<_finish_feed>  =  #param_f_feed
	#<_finish_cut>   =  #param_fc_dpt
	
	o<#self_id1> if [#param_mode EQ 0]
		G96 D#param_speed S#param_surf_speed
	o<#self_id1> else
		G97 S#param_speed
	o<#self_id1> endif
	
	o<#self_id2> if [#<_spindle_dir> GT 0]
		M#<_spindle_dir>
		G4 P#<_spindle_speed_up_delay>
	o<#self_id2> endif
	
	#<_z_clear>  = [#5410 + #param_rz]
	#<_x_clear>  = [[#5410 + #param_rx] * #<_diameter_mode>]
	#<_ix_clear> = [#param_rix * #<_diameter_mode>]
	
	F#<_rough_feed>
	
	(end #sub_name)

